<template>
	<el-card shadow="never" header="事务待办">
		<el-form ref="form" label-width="120px" label-position="left" style="margin-top:20px;">
			<el-form-item label="有新的待办">
				<el-checkbox v-model="form.shortMsgNotice" @change="save">短信推送</el-checkbox>
				<el-checkbox v-model="form.emailNotice" @change="save">邮件推送</el-checkbox>
				<div class="el-form-item-msg">注意: 如当前账号未绑定手机号或邮箱，则请前往账号信息下设置对应联系方式</div>
			</el-form-item>
		</el-form>
	</el-card>
</template>

<script>
	export default {
		data() {
			return {
				startSave: false,
				form: {
					emailNotice: false,
					shortMsgNotice: false
				}
			}
		},
		watch:{

		},
		mounted() {
			this.init();

		},
		methods: {
			async init() {
				let res = await this.$API.home.personal.getLoginUserInfo.get();
				this.form.emailNotice = Boolean(res.data.emailNotice);
				this.form.shortMsgNotice = Boolean(res.data.shortMsgNotice);
				this.startSave = true
			},

			save(){
				if(!this.startSave){
					return ;
				}
				let requestParams = Object.assign({}, this.form);
				requestParams.emailNotice = requestParams.emailNotice ? 1 : 0;
				requestParams.shortMsgNotice = requestParams.shortMsgNotice ? 1 : 0;
				this.$API.home.personal.notice.put(requestParams);
			}

		}
	}
</script>

<style>
</style>
